package com.ytktt.study.week12.task7.mapper;

import com.ytktt.study.week12.task7.entity.OrderMqInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * TODO
 *
 * @author ytk
 */
@Mapper
public interface OrderMqInfoMapper {

    @Update("UPDATE tb_order_mq_info SET success_max_id = #{id} WHERE task_region = #{region}")
    int updateSuccessMaxId(@Param("region") int region, @Param("id") long id);

    @Update("UPDATE tb_order_mq_info SET error_min_id = #{id} WHERE task_region = #{region}")
    int updateErrorMinId(@Param("region") int region, @Param("id") long id);

    @Select("SELECT id, task_region AS taskRegion, success_max_id AS successMaxId, error_min_id AS errorMinId FROM tb_order_mq_info")
    List<OrderMqInfoEntity> selectAll();

    @Select("SELECT success_max_id AS successMaxId FROM tb_order_mq_info WHERE task_region = #{region}")
    Long selectSuccessMaxIdByRegion(int region);
}
